package cn.edu.scau.cmi.yangzhichao.factory;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextArea;
import javafx.scene.text.Font;

public class InsuranceView2Controller {
    private String insString;
    @FXML
    private TextArea textArea;
    @FXML
    private ComboBox comboBox;
    @FXML
    private void initialize(){
        ObservableList<String> options= FXCollections.observableArrayList("司机受伤","车损坏");
        comboBox.setItems(options);
        textArea.setFont(Font.font("宋体",20));
        insString="司机受伤";
        comboBox.valueProperty().addListener(new ChangeListener() {
            @Override
            public void changed(ObservableValue observable, Object oldValue, Object newValue) {
                insString=(String)newValue;
                handleSubmit();
            }
        });
    }
    @FXML
    public void handleSubmit(){
        if(insString.equals("司机受伤")){
            InsuranceFactory factory=new BodyInjuryInsuranceFactory();
            textArea.setText(factory.getInstance(insString).getMessage());
        }else if(insString.equals("车损坏")){
            InsuranceFactory factory=new CarInsuranceFactory();
            textArea.setText(factory.getInstance(insString).getMessage());
        }
    }
}

